# -*- coding:utf-8 -*-
from flask import request, jsonify, abort
from flask_cors import CORS
from com.zzh.dao_v2.viewAreaDao import ViewAreaDao

from . import app

CORS(app, supports_credentials=True)


@app.route('/find_view_area', methods=['GET'])
def find_view_area():
    """
    查询 view_area
    :return:
    """
    info = ViewAreaDao().findInfo()
    if info:
        return jsonify({"info": info, "message": {"code": 1, "status": "success"}})
    else:
        return jsonify({"message": {"code": 0, "status": "error"}})


@app.route('/find_view_area_by_conditions', methods=['POST'])
def find_view_area_by_conditions():
    if not request.json:
        abort(400)
    try:
        province_id = request.json.get('province_id','')
        city_id = request.json.get('city_id', '')
        district_id = request.json.get('district_id', '')
    except:
        return jsonify({"message": {"code": 0, "status": "为传入指定参数"}})

    info = ViewAreaDao().findByCondition(province_id=province_id,city_id=city_id,district_id=district_id)
    return jsonify({"info": info, "message": {"code": 1, "status": "success"}})
